﻿	      <?php include("conn.php");
             mysql_query('SET NAMES UTF8'); 

	  

class MyPrizeBean
{
	public $ordersid;
	public $totalnum;
	public $title;
	public $name;
	public $price;
	public $images;
	public $goodsid;
	public $number;
	public $gname;
	public $numbers;
	public $yuanjia;
	public $brand;
	public $produce;
	public $state;
	public $zongjia;
	public $sd;
	public $sum;
    public $shopid;
    public $tuihuoid;
    public $msg;
	function __construct($ordersid,$totalnum,$title,$name,$price,$images,$goodsid,$number,$gname,$numbers,$yuanjia,$brand,$produce,$state,$zongjia,$sd,$sum,$shopid,$tuihuoid,$msg)
	{
		$this->ordersid    = $ordersid;
		$this->totalnum    = $totalnum;
		$this->title =$title;
		$this->name      = $name;
		$this->price = $price;
		$this->images     = $images;
		$this->goodsid    = $goodsid;
		$this->number    = $number;
		$this->gname   = $gname;
		$this->numbers    = $numbers;
		$this->yuanjia    = $yuanjia;
		$this->brand    = $brand;
		$this->produce   = $produce;
		$this->state    = $state;
		$this->zongjia    = $zongjia;
		$this->sd    = $sd;
		$this->sum    = $sum;
		$this->shopid    = $shopid;
		$this->tuihuoid    = $tuihuoid;
		$this->msg    = $msg;
	}
}





	$uid=2;
	$sta=$_REQUEST[sta];


	 // $srat1=mysql_query("update goodsorders  set bits='".$ling."' where shopid='".$_REQUEST['shopid']."' and state='".$_REQUEST[sta]."'   ");
	$prize = array();
	 $rert31=mysql_query("select *from shop where shopid='".$_REQUEST[shopid]."'");
   $rowf1=mysql_fetch_array($rert31);
if ($sta=='1' || $sta=='7') {
	$rert30=mysql_query("select *from goodsorders where shopid='".$_REQUEST[shopid]."'  and (state='1' or state='7') order by ordersid desc");
}else{
	$rert30=mysql_query("select *from goodsorders where shopid='".$_REQUEST[shopid]."'  and state='".$sta."'order by ordersid desc");
} 
while($rowf=mysql_fetch_array($rert30)){
$goodsnames='';
$prices='';
$numbers='';
$goodsids='';
$totalnum=0;
	
$rert31=mysql_query("select *from car where ordersid ='".$rowf[ordersid]."'");

while ($rowf1=mysql_fetch_array($rert31)) {
    	$goodsnames.=','.$rowf1[goodsname];
		$prices.=','.$rowf1[price];
		$numbers.=','.$rowf1[number];
		$totalnum+=$rowf1[number];
		$rert33=mysql_query("select *from goods where goodsid ='".$rowf1[goodsid]."'");
		$rowf3=mysql_fetch_array($rert33);
		$goodsids.=','.$rowf3[goodsid];
		$ime=$rowf3[images];
		$de = array();
		$de=explode("," ,$ime);
		$images=$de[0];
}
$goodsnames=substr($goodsnames, 1);
$prices=substr($prices, 1);
$numbers=substr($numbers, 1);
$goodsids=substr($goodsids, 1);
$goodsids=explode(',', $goodsids);

$yanse=$rowf1[caizhi].$rowf1[caizhi];
$rert34=mysql_query("select SUM(number) as total from car where ordersid ='".$rowf[ordersid]."'");
$rowf4=mysql_fetch_array($rert34);
   
 $rert32=mysql_query("select *from shop where  shopid ='".$rowf[shopid]."'");
$rowf2=mysql_fetch_array($rert32);

// 查找分类类别
$query = mysql_query("select * from categroy_type where id=(select categroy_type_id from categroy where cateid='".$rowf2[leimu]."')");
$categroy_type = mysql_fetch_assoc($query);
// 查找分类类别 end

// 查找快递公司
$query=mysql_query("select * from express_delivery where id=".$rowf[kuaidi]);
$express_delivery=mysql_fetch_assoc($query);
// 查找快递公司 end
// $rert33=mysql_query("select *from goods where goodsid ='".$rowf1[goodsid]."'");
// $rowf3=mysql_fetch_array($rert33);

// 查询退货状态
$query = mysql_query("select * from tuihuo where ordersid=".$rowf[ordersid]);
$tuihuo = mysql_fetch_assoc($query);
if ($tuihuo[state]==1) {
	$tuihuoTip = "申请退货,待商家审核";
}elseif ($tuihuo[state]==2){
	//$tuihuoTip = "商家通过退货申请,待平台审核";
	$tuihuoTip = "商家通过退货申请";
}elseif ($tuihuo[state]==3) {
	//$tuihuoTip = "商家拒绝退货申请,待平台审核";
	$tuihuoTip = "商家拒绝退货申请";
}elseif ($tuihuo[state]==4){
	//$tuihuoTip = "平台通过退货申请";
	$tuihuoTip = "商户已确认退货";
}elseif ($tuihuo[state]==5) {
	//$tuihuoTip = "平台拒绝退货申请";
	$tuihuoTip = "厂商已确认收货";
}elseif ($tuihuo[state]==6) {
	$tuihuoTip = "退货完成";
}
// 查询退货状态

// 订单类型（海淘为0，快购为1）
$type = $rowf[type];
// 订单类型（海淘为0，快购为1） end

if ($type == 0) {
	if($rowf[state]=="0")
	{
		$state="0";
		$sds=  "待付款";
	}elseif ($rowf[state]=="1") {
		$state="1";
		$sds=  "<button onclick=\"take('".$rowf[ordersid]."',this, '".$categroy_type[is_logistics]."',8)\">
		接单
	</button>
	<button onclick=\"take('".$rowf[ordersid]."',this, '".$categroy_type[is_logistics]."',9)\">
		拒绝
	</button>
	";
	}
	else if($rowf[state]=="8" ){
		$state="8";
	// $sds=  "<button onclick=\"shouhuo('".$rowf[ordersid]."')\">
	//    确认收货
	//    </button>
	// ";
		$sds=  "<button onclick=\"fahuo('".$rowf[ordersid]."',this, '".$categroy_type[is_logistics]."')\">
		发货
	</button>
	";
	}elseif ($rowf[state]=="7") {
		$state="7";
		$sds =  "<button onclick=\"fahuo('".$rowf[ordersid]."',this, '".$categroy_type[is_logistics]."')\">
		发货
	</button>
	";
	}
	else if($rowf[state]=="2" )
	{
		$state="2";
	//$sds=  "待确定";
		$sds=  "已发货";
	}else if($rowf[state]=="3")
	{
		$state="3";
		$sds=  "待评价 ";
	}
	else if($rowf[state]=="4")
	{
		$state="4";
		$sds=$tuihuoTip;
	}
	else if($rowf[state]=="5"){
		$state="5";
		$sds=  "交易完成";
	}
	elseif ($rowf[state]=="9") {
		$state="9";
		$sds=  "已拒绝";
	}
	else {
		$state="6";
		$sds=  "交易关闭";
	}
}elseif ($type == 1){
	if($rowf[state]=="0"){
			$state="0";
			$sds="待付款";
	}else if ($rowf[state]=="1") {
			$state="1";
			$sds=  "<button onclick=\"take('".$rowf[ordersid]."',this, '".$categroy_type[is_logistics]."',8)\">
			接单
		</button>
		<button onclick=\"take('".$rowf[ordersid]."',this, '".$categroy_type[is_logistics]."',9)\">
			拒绝
		</button>
		";
	}else if($rowf[state]=="8" ){
		$state="8";
		$sds = "<button onclick=\"shouhuo('".$rowf[ordersid]."',this, '".$categroy_type[is_logistics]."')\">
		确认送达</button>";
	}else if($rowf[state]=="3"){
	// $state="待评价";
		$state="3";
		$sds=  "待评价";
	}else if($rowf[state]=="5"){
		$state="5";
		$sds=  "完成";
	}
}

   // $ime=$rowf3[images];
			// 	$de = array();
			// 	$de=explode("," ,$ime);
			// 	$images=$de[0];	
// 如果sta=4即订单状态为退货状态,需要查询退货id
$query = mysql_query("select * from tuihuo where ordersid=".$rowf[ordersid]);
$tuihuo = mysql_fetch_assoc($query);
if (is_array($tuihuo)) {
	$tuihuoid=$tuihuo[id];
}else{
	$tuihuoid=0;
}
// 如果sta=4即订单状态为退货状态,需要查询退货id	
			$prize[] = new MyPrizeBean($rowf['ordersid'],$totalnum,$goodsnames,$rowf2['name'],$prices,$images,$goodsids[0],$rowf1['number'],$rowf3['name'],$rowf['numbers'],$rowf3['yuanjia'],$rowf3['brand'],$yanse,$state,$rowf['totalprice'],$sds,$rowf4['total'],$rowf['shopid'],$tuihuoid,$rowf['msg']);
		
	}

echo json_encode($prize);


?>